package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.RecorderListModel;
import com.banshuibao.bsb_android.util.TimeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangpan on 2017/12/28.
 */

public class RecorderListAdapter extends BaseAdapter {
    Context context;
    List<RecorderListModel.DataBean> list;

    public RecorderListAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }
    public void up(List<RecorderListModel.DataBean> list){
        if(this.list!=null){
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    public void down(List<RecorderListModel.DataBean> list){
        if(this.list!=null){
            this.list.clear();
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }


    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public RecorderListModel.DataBean getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view == null){
            view = View.inflate(context, R.layout.recorder_list_item_layout,null);
            viewHolder = new ViewHolder();
            viewHolder.tv = view.findViewById(R.id.name);
            viewHolder.date = view.findViewById(R.id.date);
            viewHolder.status = view.findViewById(R.id.status);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv.setText(list.get(i).getQuestion());
        long createDate = list.get(i).getCreateDate();
        String date = TimeUtil.format(createDate);
        viewHolder.date.setText(date);
        /**
         * 问题的状态（0 初始待审核 1 审核通过 2 审核不通过 3 补录审核中 4补录审核通过 5补录审核不通过）
         */
        String status = list.get(i).getStatus();
        switch (status){
            case "0":
                viewHolder.status.setText("待审核");
                viewHolder.status.setTextColor(context.getResources().getColor(R.color.status_color));
                viewHolder.status.setBackgroundResource(R.drawable.recorder_toaudit_shape);
                break;
            case "1":
                viewHolder.status.setText("审核通过");
                viewHolder.status.setBackgroundResource(R.drawable.recorder_pass_shape);
                viewHolder.status.setTextColor(context.getResources().getColor(R.color.status_pass));
                break;
            case "2":
                viewHolder.status.setText("审核不通过");
                viewHolder.status.setBackgroundResource(R.drawable.recorder_no_pass_shape);
                viewHolder.status.setTextColor(context.getResources().getColor(R.color.status_color_two));
                break;
            case "3":
                viewHolder.status.setText("补录审核中");
                viewHolder.status.setBackgroundResource(R.drawable.recorder_toaudit_shape);
                viewHolder.status.setTextColor(context.getResources().getColor(R.color.status_color));
                break;
            case "4":
                viewHolder.status.setText("补录审核通过");
                viewHolder.status.setBackgroundResource(R.drawable.recorder_pass_shape);
                viewHolder.status.setTextColor(context.getResources().getColor(R.color.status_pass));
                break;
            case "5":
                viewHolder.status.setText("补录审核不通过");
                viewHolder.status.setBackgroundResource(R.drawable.recorder_no_pass_shape);
                viewHolder.status.setTextColor(context.getResources().getColor(R.color.status_color_two));
                break;
        }
        return view;
    }

    class ViewHolder{
        TextView tv;
        TextView date;
        TextView status;
    }
}
